package cn.com.taurus.controller.datatable;

import cn.com.taurus.bean.ClientAccounts;
import cn.com.taurus.biz.AdminLogBiz;
import cn.com.taurus.biz.ClientBiz;
import cn.com.taurus.biz.FundCompanyBiz;
import cn.com.taurus.entity.AdminLog;
import cn.com.taurus.entity.Client;
import cn.com.taurus.entity.FundCompany;
import cn.com.taurus.util.Log;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Controller
public class ClientController {
    @Autowired
    ClientBiz clientBiz;

    @RequestMapping("/backgroundHomepage")
    public String backgroundHomepage() {
        return "supermanager/BackgroundHomepage";
    }

    @RequestMapping("/client")
    public String client() {
        return "datatable/client";
    }

    @RequestMapping("/updateClient")
    @Log(operation = "修改客户信息",type = 2)
    public String updateClient(@ModelAttribute ClientAccounts clientAccounts){
        System.out.println(clientAccounts);
        clientBiz.updateClientById(clientAccounts);
        return "datatable/client";
    }

    /**
     * 模糊查询
     * @param pageNum 几条
     * @param pageSize 数量
     * @param clientAccounts 客户对象
     * @return
     */
    @ResponseBody
    @RequestMapping("/conditionSelectClient")
    @Log(operation = "条件查询客户信息",type = 1)
    public HashMap conditionSelectClient(Integer pageNum, Integer pageSize, ClientAccounts clientAccounts){
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<ClientAccounts> rule = clientBiz.findClientAccount(clientAccounts);
        PageInfo<ClientAccounts> pageInfo = new PageInfo<>(rule);
        System.out.println("数据："+pageInfo.getPages());
        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());
        return map;
    }

    /**
     * 分页
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectClient")
    public HashMap selectClient(Integer pageNum,Integer pageSize){
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<ClientAccounts> rule = clientBiz.selectAllClientAccount();
        PageInfo<ClientAccounts> pageInfo = new PageInfo<>(rule);
        System.out.println("数据："+pageInfo.getPages());
        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());
        System.out.println(map);
        return map;
    }
}
